--[[
	GMod Last Man Standing, a gamemode for Garry's Mod
    Copyright (C) 2012 Wickex

    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
]]

local plym = FindMetaTable("Player")
if not plym then return end

function plym:ShouldSpawn()
	if not self:IsSpec() and not self:IsSurvivalist() then return false end
	return true
end

function plym:StripAll()
	self:StripAmmo()
	self:StripWeapons()
end

function plym:SpawnRound()
	if not self:ShouldSpawn() then return false end
	if self:Team() == TEAM_SPEC then
		self:UnSpectate()
	end
   
	self:StripAll()
	self:SetTeam(TEAM_SURVIVALIST)
	self:Spawn()
   
	return true
end

local oldSpectate = plym.Spectate
function plymeta:Spectate(type)
   oldSpectate(self, type)

   self:SetNoTarget(true)

   if type == OBS_MODE_ROAMING then
      self:SetMoveType(MOVETYPE_NOCLIP)
   end
end

local oldUnSpectate = plym.UnSpectate
function plymeta:UnSpectate()
   oldUnSpectate(self)
   self:SetNoTarget(false)
end
